#include "BasicGeometry.h"
#include <e32math.h>

/*
 * class TRealVector
 */

TRealVector::TRealVector():iX(0.0f),iY(0.0f)
	{
	}

TRealVector::TRealVector( TReal aX, TReal aY ):iX(aX),iY(aY)
	{
	}

TReal TRealVector::GetLength()
	{
	TReal squar = iX * iX + iY * iY;
	if ( squar == 0.0f )
		{
		return 0.0f;
		}
	TReal sqrt = 0.0f;
	Math::Sqrt( sqrt, squar );
	return sqrt;	
	}

TRealVector TRealVector::GetUnit()
	{
	TReal len = GetLength();
	if( len == 0.0f )
		{
		return TRealVector();
		}
	return TRealVector( iX/len, iY/len );
	}

TRealVector TRealVector::Mirror( TRealVector aVector )
	{
	if( aVector.iX == 0.0f && aVector.iY == 0.0f )
		{
		return TRealVector();
		}
	TRealVector bank = aVector.GetUnit();
	TRealVector src = GetUnit();
	TReal cosin = bank * src;
	if( cosin <= 0.0f )
		{
		bank = TRealVector() - bank;
		cosin = 0.0f - cosin;
		}
	TRealVector sum = bank * ( GetLength() * cosin * 2.0f );	
	return sum - TRealVector(iX,iY);
	}

void TRealVector::operator +=( TRealVector aDel )
	{
	iX += aDel.iX;
	iY += aDel.iY;
	}

void TRealVector::operator *= ( TReal aFactor )
	{
	iX *= aFactor;
	iY *= aFactor;
	}

TRealVector operator * ( TRealVector aVector, TReal aFactor )
	{
	return TRealVector( aVector.iX * aFactor, aVector.iY * aFactor );
	}
TReal operator * ( TRealVector aVec1, TRealVector aVec2 )
	{
	return aVec1.iX * aVec2.iX + aVec1.iY * aVec2.iY;
	}
TRealVector operator + ( TRealVector aVec1, TRealVector aVec2 )
	{
	return TRealVector( aVec1.iX + aVec2.iX, aVec1.iY + aVec2.iY );
	}

TRealVector operator - ( TRealVector aVec1, TRealVector aVec2 )
	{
	return TRealVector( aVec1.iX - aVec2.iX, aVec1.iY - aVec2.iY );
	}


/*
 * class TRealPoint
 */

TRealPoint::TRealPoint():iX(0.0f),iY(0.0f)
	{
	}

TRealPoint::TRealPoint( TReal aX, TReal aY ):iX(aX),iY(aY)
	{
	}

void TRealPoint::operator += ( TRealVector aVec )
	{
	iX += aVec.iX;
	iY += aVec.iY;
	}

TRealPoint operator + ( TRealPoint aPoint, TRealVector aVec )
	{
	return TRealPoint( aPoint.iX + aVec.iX, aPoint.iY + aVec.iY );
	}

TRealPoint operator - ( TRealPoint aPoint, TRealVector aVec )
	{
	return TRealPoint( aPoint.iX - aVec.iX, aPoint.iY - aVec.iY );
	}
